package co.com.inventarios.persistencia;

import java.util.List;
import java.util.logging.Level;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import co.com.inventarios.modelo.Probodega;
import co.com.inventarios.modelo.Prounimed;


public class QueryProUnimedDAO {
	
	private EntityManager getEntityManager() {
		return EntityManagerHelper.getEntityManager();
	}
	
	
	public List<Prounimed> buscarTodosProUnimed(String codigo) {
		try {
			final String queryString = "select model from Prounimed model where model.producto.procodigo='"+codigo
			        +"' AND model.producto.procodigo <> '.' order by model.unimed.umdcodigo DESC";
			Query query = getEntityManager().createQuery(queryString);
			return query.getResultList();
		} catch (RuntimeException re) {
			EntityManagerHelper.log("find by property name failed",
					Level.SEVERE, re);
			throw re;
		}
	}
	
	public List<Prounimed> findByPropertys_all(String propiedad, String valor ,String espresion) throws Exception {

		EntityManagerHelper.log("finding Prounimed instance with property: "
				+ propiedad + ", value: " + propiedad, Level.INFO, null);
		try {
			getEntityManager().clear();
			final String queryString = "select model from Prounimed model where model."+propiedad+" = '"
					+ valor + "'  " + "  "+espresion+"  ";
			Query query = getEntityManager().createQuery(queryString);

			return query.getResultList();
		} catch (RuntimeException re) {
			EntityManagerHelper.log("find by property name failed",
					Level.SEVERE, re);
			throw re;
		}
	}	

}
